#include<iostream>
#include<vector>

using namespace std;

const int N=1e6;
vector<int> primes;
bool st[N+1];
auto Init=[]
{
    for(int i=2;i<=N;++i)
    {
        if(!st[i]) primes.emplace_back(i);
        for(int j=0;primes[j]<=N/i;++j) 
        {
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break;
        }
    }
    return 0;
}();

class Solution {
public:
    vector<int> closestPrimes(int left, int right) {
        int p=-1,q=-1;
        int i=lower_bound(primes.begin(),primes.end(),left)-primes.begin();
        for(;i+1<primes.size()&&primes[i+1]<=right;++i)
        {
            if(p<0 || primes[i+1]-primes[i]<q-p) p=primes[i],q=primes[i+1];
        }
        return {p,q};
    }
};